package com.thoughtworks.preuniversity.biblioteca;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by padmavb on 6/20/14.
 */
public class Login extends MenuOperation{

    Application application;
    static User user;
    public Login(Application application) {

        this.application = application;
    }


    @Override
    void doCorrespondingOperation(Library library) {
        
        RegisteredUsers registeredUsers=new RegisteredUsers();

        List<String> loginDetails=takeUserLoginDetails();
        User user=registeredUsers.validateLoginDetails(loginDetails);
        if(user!=null){

            Login.user=user;
            application.loginOrNot();
        }
        else{

            new UserInterface().displayMessage("Please enter valid details");

        }

    }


    @Override
    String giveJobOfClass() {
        return "Login";
    }

    private List<String> takeUserLoginDetails(){

        List<String> loginDetails=new ArrayList<String>();

        String libraryNumber;
        String password;

        UserInterface userInterface=new UserInterface();
        userInterface.displayMessage("Enter Library Number");
        libraryNumber=userInterface.readLibraryNumber();

        userInterface.displayMessage("Enter Password");
        password=userInterface.readPassword();

        loginDetails.add(libraryNumber);
        loginDetails.add(password);

        return loginDetails;
    }

}
